package com.glory.erp.auth.resources.action;

import java.util.List;

import com.glory.erp.auth.resources.service.ResourcesService;
import com.glory.erp.auth.resources.bean.Resources;
import com.glory.erp.auth.resources.bean.ResourcesQuery;
import com.glory.erp.auth.base.BaseAction;

public class ResourcesAction extends BaseAction {

	public Resources resources = new Resources();
	public ResourcesQuery resourcesQuery = new ResourcesQuery();

	private ResourcesService resourcesService;

	public void setResourcesService(ResourcesService resourcesService) {
		this.resourcesService = resourcesService;
	}

	/**
	 * 
	 * @Description: 资源信息展示
	 * @Title: list
	 * @Author: 樊双峰
	 * @Param: @return
	 * @return: String
	 * @Date: 2018年5月20日 下午7:45:10
	 * @throws
	 */
	public String list() {
		setDataTotal(resourcesService.getCount(resourcesQuery));
		List<Resources> resourcesList = resourcesService.findAll(
				resourcesQuery, pageNum, pageCount);
		put("resourcesList", resourcesList);
		return LIST;
	}

	/**
	 * 
	 * @Description: 跳转至添加、修改页面
	 * @Title: addView
	 * @Author: 樊双峰
	 * @Param: @return
	 * @return: String
	 * @Date: 2018年5月20日 下午7:45:23
	 * @throws
	 */
	public String addView() {
		if (resources.getUuid() != null) {
			resources = resourcesService.findById(resources.getUuid());
		}
		return ADD;
	}

	/**
	 * 
	 * @Description: 资源添加、修改
	 * @Title: saveAndUpdate
	 * @Author: 樊双峰
	 * @Param: @return
	 * @return: String
	 * @Date: 2018年5月20日 下午7:46:39
	 * @throws
	 */
	public String saveAndUpdate() {
		if (resources.getUuid() == null) {
			resourcesService.save(resources);
		} else {
			resourcesService.update(resources);
		}
		return TO_LIST;
	}

	/**
	 * 
	 * @Description: 资源删除
	 * @Title: delete
	 * @Author: 樊双峰
	 * @Param: @return
	 * @return: String
	 * @Date: 2018年5月20日 下午7:47:11
	 * @throws
	 */
	public String delete() {
		resourcesService.delete(resources);
		return TO_LIST;
	}
}